<?php


/**
 * Controler for lab management.
 * @package modules.dept_laboratory.controllers
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class C_ParacliniqueConfig extends Controller {
    private $logger ;
    private $labProcessor;

    function __construct($template_mod = "general") {
        parent::Controller();
        $this->setLayout('admin');
        $this->logger = LoggerManager::getLogger('local.controllers.C_ParacliniqueConfig');
        $this->template_mod = $template_mod;
        $this->view->path="default";
    }
    /**
     * Render lab admin page.
     * @return html
     */
    public function actionConfig() {
        $this->logger->info('Start actionConfig');
        $paraList = Utils::getEnumArrayKey(EnumerationConstant::PARACLINIC_TYPE);
        $paymentTypes = Utils::getEnumArrayKey(EnumerationConstant::PAYMENT_TYPE);
        $listRooms = Celini::newOrdo("Room")->listRooms(); 
        $paraConfigList = Celini::newOrdo("ParacliniqueConfig")->listParaclinicConfig();
        $this->assign('paraList' , $paraList);
        $this->assign('paraConfigList' , $paraConfigList);
        $this->assign('paymentTypes', $paymentTypes);
        $this->assign('listRooms', $listRooms);
        //var_dump($paraConfigList);
        $html = $this->view->render('paraclinique_config.html');        
        $this->logger->info('Finish actionConfig');
        return $html;
    }
    public function actionSaveAjax() {
        $this->logger->info('Start actionSaveAjax');
        $result = array('error'=>array('code'=>CoreErrorCode::NORMAL,'mess'=>''),'result'=>'');

        try {
                $paras = $_POST['paraEnum'];
                $roomIds = $_POST['roomId'];
                $paymentTypes = $_POST['paymentType'];                        
                for ($index = 0; $index < count($paras); $index++) {
                    $paraConfigObj = Celini::newOrdo('ParacliniqueConfig');                    
                    $data = array();
                    $data['enum_paraclinic_type'] = $paras[$index];
                    $data['enum_payment_type'] = $paymentTypes[$index];
                    $data['room_id'] = $roomIds[$index];                    
                    $paraConfigObj->saveConfig($data); 
                                        
                }

        }  catch (Exception $ex) {
            $result['error']['code'] = CoreErrorCode::COMMON_ERROR;
            $result['error']['mess'] = CoreErrorCode::getErrorMess(CoreErrorCode::COMMON_ERROR);
            $logger->error('actionSaveAjax fail. Error detail: '. $ex->getMessage());
        }

        $this->logger->info('Finish actionSaveAjax');
        return json_encode($result);
    }

   


}
?>